<?php  
class AccessController extends AuthController{
	/**
	 * 角色权限设置
	 */
	public function set(){
		if (IS_POST) {
			// p($_POST);exit;
			$db=M('access');

			//写入权限之前先删除当前角色所有权限再进行添加
			$db->where("rid=".$_POST['rid'])->del();

			if (!empty($_POST['access'])) {

				foreach ($_POST['access'] as $controller  =>  $action ) {

					foreach ($action as $a) {

						$data['rid']=$_POST['rid'];//主键

						$data['module']='Admin';	//模块

						$data['controller']=$controller;//控制器
						
						$data['action']=$a;//动作

						$db->add($data);//逐条写入数据库
					}
				}
			}
			$this->success('设置成功');
		}else{

			$sql="SELECT * FROM shop_node";

			$node=M()->query($sql);

			$node=Data::channelLevel($node,0,'&nbsp;','nid');


			$map['rid']=Q("get.rid",0,'intval');

			$controller=M('access')->where($map)->getField('controller',true);

			// $action=M('access')->where($map)->getField('action',true);

			$action=M('access')->where($map)->all();

			foreach ($action as $a) {
				$data[$a['controller']][]=$a['action'];
			}

			$this->assign('node',$node);
			// p($node);
			$this->assign('controller',$controller);
			// p($controller);
			$this->assign('action',$data);
			// p($data);exit;
			$this->display();
		}
	}
}
?>